package com.mode.observer.pattern;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description:
 * @Author: zyf
 * @Time: 2020/9/29 11:19
 */
public class RealSubject implements Subject {
    private List<Observer> observerList = new ArrayList<>();


    @Override
    public void attach(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    public void notifyChanged() {
        for (Observer observer : observerList) {
            observer.update();
        }
    }
}